﻿using ITXHWEB.Models;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Web.Mvc;
using WPFExcelReport;
using WPFExcelReport.Helpers;
using ITXHWEB.Infrastructure;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace ITXHWEB.Controllers
{
    public partial class WBBSTController
    {
        [ChildActionOnly]
        public ActionResult NTP(string returnUrl)
        {
            ModelState.Clear();
            ViewBag.ReturnUrl = returnUrl;
            MWB.REMARK = INFO;
            return PartialView(MWB);
        }
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult NTP(WBBSTModel model, string returnUrl)
        {
            try
            {
                ModelState.Clear();
                if(model.NEWTP==null)
                {
                    model.NEWTP = "0000";
                }
                if (model.NEWTP.Trim().Length > 0)
                {
                    MWB.NEWTP = Helper.Right("0000" + model.NEWTP, 4);
                }
                else
                {
                    MWB.NEWTP = Helper.Right("0000" + (Convert.ToInt16(MWB.TP) + 1), 4);
                }
                if (Convert.ToInt16(MWB.NEWTP) > Convert.ToInt16(MWB.TP))
                {
                    MWB.TP = MWB.NEWTP;
                }
                MWB.PCS = 0;
                MWB.QMTR = 0.0;
                MWB.IsTPReady = true;
            }
            catch (Exception ex)
            {
                INFO = ex.Message;
                Tracer.Error(ex.StackTrace, ex);
            }
            return RedirectToAction(MAPP, MAPP);
        }
    }
}
